home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / mail / pine3.96.tar.gz / pine3.96.tar / pine3.96 / pine / osdep / includer.c < prev    next >
C/C++ Source or Header  |  1996-03-14  |  2KB  |  76 lines

  1. #if !defined(lint) && !defined(DOS)
  2. static char rcsid[] = "$Id: includer.c,v 5.4 1996/03/15 04:40:33 mikes Exp $";
  3. #endif
  4. #include <stdio.h>
  5. #include <string.h>
  6.  
  7. /*
  8.  * Inflexible cat with include files.
  9.  * The include lines must look exactly like  include(filename)  with no
  10.  * spaces before the include, or between the parens and the surrounding
  11.  * characters.
  12.  *
  13.  * This probably ought to just be a script that uses "cat".
  14.  */
  15. main(argc, argv)
  16. int argc;
  17. char *argv[];
  18. {
  19.   FILE * infile = stdin;
  20.   FILE * outfile = stdout;
  21.  
  22.   if (argc > 1) {
  23.     if ((infile = fopen(argv[1], "r")) == NULL) {
  24.       fprintf(stderr, "includer: can't open '%s' for input\n", argv[1]);
  25.       exit(1);
  26.     }
  27.     if (argc > 2) {
  28.       if ((outfile = fopen(argv[2], "w")) == NULL) {
  29.     fprintf(stderr, "includer: can't create '%s'\n", argv[2]);
  30.     exit(1);
  31.       }
  32.     }
  33.   }
  34.   readfile(infile, outfile);
  35.   exit(0);
  36. }
  37.  
  38. readfile(fpin, fpout)
  39. FILE *fpin, *fpout;
  40. {
  41.     char line[BUFSIZ+1];
  42.     char tmp[BUFSIZ+1];
  43.     FILE *fp;
  44.     char *p, *fname, *fend;
  45.  
  46.     while ((p = fgets(line, BUFSIZ, fpin)) != NULL) {
  47.  
  48.         if (!strncmp("include(", p, strlen("include("))) {
  49.  
  50.             /* do include */
  51.             fname = strchr(p, '(');
  52.             if (fname == NULL) {
  53.                 fprintf(stderr, "Can't find include file %s\n", p);
  54.                 exit(1);
  55.             }
  56.             fname++;
  57.             fend = strrchr(fname, ')');
  58.             if (fend == NULL) {
  59.                 fprintf(stderr, "Can't find include file %s\n", p);
  60.                 exit(1);
  61.             }
  62.             *fend = '\0';
  63.             if ((fp = fopen(fname, "r")) == NULL) {
  64.                 fprintf(stderr, "Can't open include file %s\n", fname);
  65.                 exit(1);
  66.             }
  67.             readfile(fp, fpout);
  68.             fclose(fp);
  69.  
  70.         /* skip if comment line (begins with ;) */
  71.         }else if (*p != ';') {
  72.             fputs(p, fpout);
  73.         }
  74.     }
  75. }
  76.